import time
import datetime
import random
import calendar


def get_current_month_start_and_end(date):
    """
    :return: 本月第一天日期和本月最后一天日期
    """
    if date.count('-') != 2:
        raise ValueError('- is error')
    year, month = str(date).split('-')[0], str(date).split('-')[1]
    end = calendar.monthrange(int(year), int(month))[1]
    start_date = '%s-%s-01 00:00:00' % (year, month)
    end_date = '%s-%s-%s 23:59:59' % (year, month, end)
    return start_date, end_date


if __name__ == '__main__':
    print(get_current_month_start_and_end('2020-11-24'))

    # 计算第几周
    print(int(time.strftime("%W")) % 2 == 0)

    date_string = "2020-01-13 13:53:59"
    nowTime = datetime.datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S")
    print(datetime.datetime(nowTime.year, nowTime.month, nowTime.day).isocalendar()[1])

